﻿var userdefault = {};
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initData();
            var date = new Date();
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth()) + 1 : "" + (date.getMonth() + 1);
            $("#startMonth").val(date.getFullYear() + "-" + month);
        },
        bind: function () {
            $('#lr_save_btn').on('click', function () {
                if (!$('#form').lrValidform()) {
                    return false;
                }
                var machineCode = $("#machineCode").val();

                $.ajax({
                    url: config.base_server() + 'license/create?machineCode=' + machineCode + '&access_token=' + config.getToken().access_token,
                    data: {},
                    type: "POST",
                    dataType: "json",
                    contentType: 'application/json',
                    charset: 'UTF-8',
                    async: true,
                    cache: false,
                    success: function (res) {
                        if (res.resp_code == learun.httpCode.exception) {
                            learun.httpErrorLog(res.resp_msg);
                            res.resp_msg = '系统异常，请联系管理员！';

                            learun.alert.error(res.resp_msg);
                        } else {
                            $("#licenseCode").val(res.data);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        learun.httpErrorLog(textStatus);
                    },
                    beforeSend: function () {
                    },
                    complete: function () {
                    }
                });
            });
        },
        initData: function () {
            learun.httpAsyncGet(config.base_server() + 'license/getServerInfos', function (res) {
                learun.loading(false);
                if (res.resp_code == 200) {
                    $("#machineCode").val(res.data.cpuSerial);
                }
            });
        }
    };
    page.init();
}